package
{
	import Components.MovementComponent;
	
	import flash.display.Sprite;

	public class Attack
	{
		public var damage:Number = 1;
		public var movementComponent:MovementComponent = new MovementComponent;
		public var display:Sprite = new Sprite();
		
		public var target:IAttackable;
		public var destructCallback:Function;
		
		public function Attack()
		{
			var bg:Sprite = VTUtil.getRectOutline(5,5,0xff0000,1);
			bg.x = -bg.width/2;
			bg.y = -bg.height/2;
			display.addChild(bg);			
		}
		
		public function update(delta:int):void{
			movementComponent.update(delta);
			movementComponent.destination = target.getLocation().clone();
			if(movementComponent.isAtDestination()){
				target.inflictDamage(damage);
				this.destructCallback(this);
			}
			
			display.x = movementComponent.location.x * rts1.RATIO.x;
			display.y = movementComponent.location.y * rts1.RATIO.y;			
		}
	}
}